<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>directives</title>
</head>
<body>
<div id="directives">
    <p v-if="show">v-if效果，显示这段文本</p>
    <div v-if="show">
        {{ books }}
    </div>
    <div>
        <a v-bind:href="herfUrl">v-bind</a>
    </div>
    <div>
        <img v-bind:src="imgUrl">
    </div>
    <div>
        <span>时间监听器</span>
        <!-- 可以直接是一个内联元素 -->
        <button v-on:click="show = false">{{ buttonContent }}</button>
        <!-- 也可以是一个方法 -->
        <button v-on:click="handleClose">{{ buttonContent }}</button>
        <!-- 语法糖, v-on:click中v-on可以被@替代，v-bind可以直接被：替代，简化写法-->
        <button @click="handleClose">{{ buttonContent }}</button>
    </div>

</div>

<script src="https://unpkg.com/vue/dist/vue.min.js"></script>
<script>

    new Vue({
        el: '#directives',
        data: {
            books: [
                {name: '《Vue 项目实战》'},
                {name: '《JavaScript语言精粹》'}
            ],
            buttonContent: '内容显示',
            show: true,
            herfUrl: "https://www.baidu.com",
            imgUrl: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.16pic.com%2F00%2F88%2F44%2F16pic_8844212_s.jpg&refer=http%3A%2F%2Fimg.16pic.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1634616204&t=a7c25af5b455a1adc3acff7ede9b224e"
        },
        methods: {
            handleClose: function () {
                this.show = !this.show
                if (this.show) {
                    this.buttonContent = '显示'
                } else {
                    this.buttonContent = '隐藏'
                }

            }
        }
    })
</script>

</body>
</html>